﻿using StarPizza.Model.BaseModel;
using StarPizza.Model.Core;
using StarPizza.ViewModel.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarPizza.ViewModel.ManagerSystem
{
    class DoughAdministrator : IngredientAdministrator
    {
        DoughLister doughLister;

        private DoughVM ActualDoughVM
        {
            get { return doughLister.SelectedIngredientVM; }
        }
        protected override int ActualCost
        {
            get
            {
                if (ActualDoughVM != null)
                    return ActualDoughVM.Cost;
                else 
                    return 0;
            }
        }
        protected override int ActualPrice
        {
            get
            {
                if (ActualDoughVM != null)
                {
                    return ActualDoughVM.Price;
                }
                else {
                    return 0;
                }
            }
        }

        public int Size
        {
            get
            {
                if (ActualDoughVM != null)
                    return ActualDoughVM.Size;
                else
                    return 0;
            }
        }

        private int newSize;
        public int NewSize
        {
            get { return newSize; }
            set
            {
                if (value != newSize)
                {
                    newSize = value;
                    OnPropertyChanged("NewSize");
                }
            }
        }

        public DoughAdministrator(StarDataDataContext db, StockHandler stockHandler, DoughLister doughLister)
            : base(db, stockHandler)
        {
            this.doughLister = doughLister;
            doughLister.IngredientVMSelected += doughLister_DoughVMSelected;
            IngredientSelected();
        }

        public DoughLister DoughLister { get { return doughLister; } }

        void doughLister_DoughVMSelected(DoughVM doughVM)
        {
            IngredientSelected();
            OnPropertyChanged("Size");
        }
        public void UpdateDough()
        {
            ActualDoughVM.Cost = EditedCost;
            ActualDoughVM.Price = EditedPrice;
            ActualDoughVM.UpdateModel();
            Utility.TrySubmitChanges(db);

            IngredientUpdated();
        }
        public void CreateDough()
        {
            stockHandler.CreateDough(NewSize, NewCost, NewPrice);
        }
        public void SupplyDough()
        {
            stockHandler.SupplyDough(ActualDoughVM.WrappedDough, SupplyAmount);
        }
    }
}
